//
//  YqModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit
enum YqType:Int {
    case pa = 0
    case kpa
    case hpa
    case atm
    case mmHg
    case inHg
    case bar
    case mbar
    case psf
    case psi
    case haomiWg
    case kgfcm2
    case kgfm2
    case mPa
}

class YqModel: NSObject {
    let types = ["帕斯卡","千帕","百帕","标准大气压","毫米汞柱","英寸汞柱","巴","毫巴","磅力/平方英尺","磅力/平方英寸","毫米水柱","公斤力/平方厘米","公斤力/平方米","兆帕"]
    let signs = ["pa","kpa","hpa","atm","mmHg","in Hg","bar","mbar","psf","psi","毫米水柱","kgf/cm²","kgf/㎡","MPa"]
    
    
    func kmTall(n: Double, type: YqType, reverse: Bool = false) -> Double {
        var km3 = n
        switch type {
        case .pa:
            break
        case .kpa:
            km3 = reverse ? n / 0.001: n * 0.001
            break
        case .hpa:
            km3 = reverse ? n / 0.01: n * 0.01
            break
        case .atm:
            km3 = reverse ? n / 9.8692e-6: n * 9.8692e-6
            break
        case .mmHg:
            km3 = reverse ? n / 0.0075006: n * 0.0075006
            break
        case .inHg:
            km3 = reverse ? n / 0.0002953: n * 0.0002953
            break
        case .bar:
            km3 = reverse ? n / 0.00001: n * 0.00001
            break
        case .mbar:
            km3 = reverse ? n / 0.01: n * 0.01
            break
        case .psf:
            km3 = reverse ? n / 0.0208854: n * 0.0208854
            break
        case .psi:
            km3 = reverse ? n / 0.000145: n * 0.000145
            break
        case .haomiWg:
            km3 = reverse ? n / 0.101972: n * 0.101972
            break
        case .kgfcm2:
            km3 = reverse ? n / 0.0000102: n * 0.0000102
            break
        case .kgfm2:
            km3 = reverse ? n / 0.1019716: n * 0.1019716
            break
        case .mPa:
            km3 = reverse ? n / 1e-6: n * 1e-6
            break

            
        }
        return km3
    }

    
    func allChange(d: Double, type: YqType) -> [String] {
        let km = kmTall(n: d, type: type, reverse: true)
        
        
        
        return ["\(kmTall(n: km, type: .pa))\(signs[0])","\(kmTall(n: km, type: .kpa))\(signs[1])",
                "\(kmTall(n: km, type: .hpa))\(signs[2])","\(kmTall(n: km, type: .atm))\(signs[3])",
                "\(kmTall(n: km, type: .mmHg))\(signs[4])","\(kmTall(n: km, type: .inHg))\(signs[5])",
                "\(kmTall(n: km, type: .bar))\(signs[6])","\(kmTall(n: km, type: .mbar))\(signs[7])","\(kmTall(n: km, type: .psf))\(signs[8])","\(kmTall(n: km, type: .psi))\(signs[9])",
                "\(kmTall(n: km, type: .haomiWg))\(signs[10])","\(kmTall(n: km, type: .kgfcm2))\(signs[11])",
                "\(kmTall(n: km, type: .kgfm2))\(signs[12])","\(kmTall(n: km, type: .mPa))\(signs[13])"]

    }

}
